<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
         // 有个数组arr，现在要把arr转换成一个对象，其结构就是obj
    // 改变前
    var arr = [
      {id: 1, name: '张山', result: '80'},
      {id: 2, name: '张山', result: '90'},
      {id: 3, name: '张山', result: '100'},
      {id: 4, name: '李四', result: '60'},
      {id: 5, name: '李四', result: '70'},
      {id: 6, name: '李四', result: '80'},
    ]
   
    var obj = {}
    for (var i = 0; i < arr.length ; i++) {
        if ( !obj[arr[i].name]) {
           
            obj[arr[i].name] = arr[i]
            
        }else{
            obj[arr[i].name].push(arr[i])
        }
        
    }

    </script>
</body>
</html>